/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_RTP_UDP_SERVER_H
#define MK_RTP_UDP_SERVER_H
#include "MkRtp.h"
#include "MkSocket/MkSocket.h"

class MkApi CMkRtpUdpSocket :public CMkSocket
{
public:
    CMkRtpUdpSocket(CMkEvent* pEvent, CMkTimer* pTimer, const MkRtpPacketCallback RtpCb);
    ~CMkRtpUdpSocket();

    virtual Uint32 OnRecvFrom() override;
protected:
private:
    Uint8*                  m_pRtpBuffer;
    Uint32                  m_nMaxLen;
    MkRtpPacketCallback     m_RtpCb;
};

class MkApi CMkRtcpUdpSocket :public CMkSocket
{
public:
    CMkRtcpUdpSocket(CMkEvent* pEvent, CMkTimer* pTimer, const MkRtcpPacketCallback Cb);
    ~CMkRtcpUdpSocket();

    virtual Uint32 OnRecvFrom() override;
protected:
private:
    Uint8*                  m_pRtcpBuffer;
    Uint32                  m_nMaxLen;
    MkRtcpPacketCallback    m_RtcpCb;
};

class MkApi CMkRtpUdpServer : public CMkRtp
{
public:
    CMkRtpUdpServer(CMkEvent* pEvent, CMkTimer* pTimer);
    virtual ~CMkRtpUdpServer();

    static void SetRtcpCheckFlag(const BOOL& bCheckRtcp) { m_CheckRtcpFlag = bCheckRtcp; }
    static void SetRtcpTimeOutSec(const Uint32& TimeOutSec) { m_RtcpTimeSec = TimeOutSec; }
    Uint32 Start(const Uint16& RtpPort);
    Uint16 GetRtpPort() const;
    Uint16 GetRtcpPort() const;
    Uint32 SendRtpPacket(const CMkRtpPacket& RtpPacket, const MkString& RemoteIp, Uint16 RemotePort) override;
    Uint32 SendRtcpPacket(const CMkRtcpPacket& RtcpPacket, const MkString& RemoteIp, Uint16 RemotePort) override;
    Uint32 Release() override;
protected:
private:
private:
    CMkRtcpUdpSocket*       m_pRtcpSocket;
    CMkRtpUdpSocket*        m_pRtpSocket;
    CMkEvent*               m_pEvent;
    static BOOL             m_CheckRtcpFlag;
    static Uint32           m_RtcpTimeSec;
};

#endif
